function flatten(arr) {
  let len = arr.length;
  let newArr = [];
  for (let i = 0; i < len; i++) {
    const item = arr[i];
    if (Array.isArray(item)) {
      // 这一步的操作主要防止的是数组里面还有数组这种情况
      newArr = newArr.concat(flatten(item));
    } else {
      newArr.push(item);
    }
  }
  return newArr;
}

let arr = [1, 2, [3, 4, 5], [6, 7, [8, 9]]];
let a = flatten(arr);
console.log(a);
